// pages/myPages/personalCenter/ReceivablesInformation/createReceipt/createAAlipay/createAAlipay.js
var request = require('./request.js')

//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tempFilePaths: '../../../../../image/icon_tjtp.png',
    userICInput: '',
    alipay: '',
    name:'',
    id:'',
    proceeds_type:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      id:options.id,
    })
    that.infoCata();
  },
  userICInput: function (e) {
    this.setData({
      alipay: e.detail.value
    })
  },
  infoCata:function(){
    var that = this;
    var data = {
      access_token: wx.getStorageSync('createUser').access_token,
      id: that.data.id
    }
    request.getOne(data, function (d) {
      console.log(d)
      that.setData({
        tempFilePaths: d.data.qrcode,
        alipay: d.data.account,
        proceeds_type: d.data.proceeds_type,
        name: d.data.proceeds.name
      })
    });
  },
  UploadFront: function () {
    var that = this
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        var tempFilePaths = res.tempFilePaths
        that.setData({
          tempFilePaths: res.tempFilePaths
        })
        // console.log(res.tempFilePaths)
        wx.setStorage({ key: "tempFilePathsPay", data: tempFilePaths[0] })
      }
    })
  },
  getVerifyingCode: function () {
    var that = this
    var payCode = wx.getStorageSync('tempFilePathsPay')
    wx.uploadFile({
      url: 'https://wallet.kinlink.cn/api/gathering/up-proceed',
      header: { 'content-type': 'multipart/form-data' },
      method: 'POST',
      filePath: payCode,
      name: 'qrcode',
      formData: {
        'access_token': wx.getStorageSync('createUser').access_token,
        'id': that.data.id,
        'username':'',
        'bank_name':'',
        'proceeds_type': that.data.proceeds_type,
        'account': that.data.alipay
      },
      success: function (res) {
        var str = res.data;
        var obj = JSON.parse(str); 
        console.log(obj.message)
        if (obj.code == 200){
          wx.navigateBack({
            delta: 1
          })
          wx.showToast({
            title: obj.message,
            icon: 'succes',
            duration: 500,
            mask: true
          });
        }else{
          wx.showToast({
            title: obj.message,
            icon: 'succes',
            duration: 1000,
            mask: true
          });
        }
      }
    })
  },
  contactDelete:function(){
    var that =this;
    var data={
      access_token: wx.getStorageSync('createUser').access_token,
      id: that.data.id,
    }
    request.delProceed(data,function(d){
      console.log(d)
      if(d.code == 200){
        wx.navigateBack({
          delta: 1
        })
        wx.showToast({
          title: d.message,
          icon: 'succes',
          duration: 500,
          mask: true
        });
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      setLang: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'] : wx.T.locales['en']

    })
    wx.setNavigationBarTitle({
      title: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].ReceiptInfo : wx.T.locales['en'].ReceiptInfo
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})